package org.huawei260.TiKu.ODsuanfa;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.StringJoiner;
import java.util.stream.Collectors;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.StringJoiner;
import java.util.stream.Collectors;
/**
 * @Author: qingle
 * @Date: 2024/10/28-16:11
 * @Description: 2555 【排序】2024EVLAN资源池
 * @version: 1.0
 */
public class E_2024E_2555__排序VLAN资源池 {


//	public class Main {
		public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);

			String[] vlanArr = sc.nextLine().split(",");
			int remove = Integer.parseInt(sc.nextLine());

			System.out.println(getResult(vlanArr, remove));
		}

		public static String getResult(String[] vlanArr, int remove) {
			LinkedList<Integer[]> vlanList =
				Arrays.stream(vlanArr)
					.map(v -> Arrays.stream(v.split("-")).map(Integer::parseInt).toArray(Integer[]::new))
					.sorted((a, b) -> a[0] - b[0])
					.collect(Collectors.toCollection(LinkedList::new));

			for (int i = 0; i < vlanList.size(); i++) {
				Integer[] vlan = vlanList.get(i);

				int from = vlan[0];

				if (vlan.length > 1) {
					int to = vlan[1];

					if (remove < from || remove > to) continue;

					vlanList.remove(i);

					if (remove == from) {
						vlanList.add(i, generateRange(remove + 1, to));
					} else if (remove == to) {
						vlanList.add(i, generateRange(from, remove - 1));
					} else {
						vlanList.add(i, generateRange(remove + 1, to));
						vlanList.add(i, generateRange(from, remove - 1));
					}

					break;
				} else if (from == remove) {
					vlanList.remove(i);
					break;
				}
			}

			StringJoiner ans = new StringJoiner(",");

			vlanList.stream()
				.map(
					vlan -> {
						StringJoiner sj = new StringJoiner("-");
						for (Integer v : vlan) sj.add(v + "");
						return sj.toString();
					})
				.forEach(ans::add);

			return ans.toString();
		}

		public static Integer[] generateRange(int from, int to) {
			if (from < to) {
				return new Integer[] {from, to};
			} else {
				return new Integer[] {from};
			}
		}
	}